//******************************************************//
//              系统首页                               //
//****************************************************//

#include"my.h"

//***********超级管理员***********//
void system_admin_reboot(T_LINK **head_teacher,S_LINK **head_student)
{
    char reboot[]="reboot";
    char enter[16];
    printf("\t\t\t***");
    scanf("%s",enter);
    if(0==strcmp(enter,reboot))
    {
	FILE *REBOOT_SYSTEM;
	REBOOT_SYSTEM=fopen("sys_admin_regist_info_log.log","w");
	fclose(REBOOT_SYSTEM);
	REBOOT_SYSTEM=fopen("sys_admin_regist_info_log.log","a");
	struct regist_info sys_admin;
	strcpy(sys_admin.name,"admin");
	strcpy(sys_admin.pass_word,"admin");

	fwrite(&sys_admin,sizeof(struct regist_info),1,REBOOT_SYSTEM);
	fclose(REBOOT_SYSTEM);
	sys_admin_home(head_teacher,head_student);


    }
    else
    {
	welcome();
	welcome_chose_enter_login();

    }
}

//***********************************************//


void welcome_chose_enter_login()
{
    int welcome_chose;//登录选择
    static int error_count=0;//选择错误，每3次再次显示欢迎界面

    T_LINK *head_teacher=NULL;
    S_LINK *head_student=NULL;


    read_teacher_info(&head_teacher);
    read_student_info(&head_student);

    scanf("%d",&welcome_chose);
    getchar();
    switch(welcome_chose)
    {
	case 1:system("clear");sys_admin_login(&head_teacher,&head_student);break;//管理员登录
	case 2:system("clear");teacher_login(&head_teacher,&head_student);break;//教师登录
	case 3:system("clear");student_login(&head_teacher,&head_student);break;//学生登录
	case 4:exit_system(&head_teacher,&head_student);break;//退出系统
	case 911:system_admin_reboot(&head_teacher,&head_student);break;//初始化管理员系统（更改管理员）
	default:printf("\t\t\t   ******* 选择错误！********\n\t\t\t   ****** 请重新输入! *******\n");
		printf("\t\t\t   ");
		error_count++;
		if(error_count>2)
		{
		    error_count=0;
		    sleep(1);
		    system("clear");
		    welcome();
		}
		welcome_chose_enter_login();
    }

}

void welcome()
{
    system("clear");
    printf("\n\t\t***************************************************************\t\t\n");
    printf("\n\t\t************          欢迎使用信息管理系统       **************\t\t\n");
    printf("\n\t\t************                                     **************\t\t\n");
    printf("\n\t\t************                                     **************\t\t\n");
    printf("\n\t\t************                                     **************\t\t\n");
    printf("\n\t\t************            1.管理员登录             **************\t\t\n");
    printf("\n\t\t************            2.教师登录               **************\t\t\n");
    printf("\n\t\t************            3.学生登录               **************\t\t\n");
    printf("\n\t\t************            4.退出系统               **************\t\t\n");
    printf("\n\t\t************                                     **************\t\t\n");
    printf("\n\t\t***************************************************************\t\t\n");
    printf("\t\t\t   ");
}

void exit_system(T_LINK **head_teacher,S_LINK **head_student)
{
    system("clear");
    printf("\n\t\t***********************************************************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t************            就这样了！           **************\t\t\n");
    printf("\n\t\t************            BYE  BYE             **************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t************                                 **************\t\t\n");
    printf("\n\t\t***********************************************************\t\t\n");

    free_teacher_link(head_teacher);
    free_student_link(head_student);
}

int main()
{
    welcome();
    welcome_chose_enter_login();
    return 0;
}

